// pages/statistics/wbj/index.js
import {
  getxmTj,
} from '../../api/statistics'
import * as echarts from '../../components/ec-canvas/echarts';
let chart = null;
var option = {
  tooltip: {
    trigger: 'axis',
    axisPointer: { // 坐标轴指示器，坐标轴触发有效
      type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
    },
    confine: true
  },
  legend: {
    data: []
  },
  grid: {
    left: 20,
    right: 20,
    bottom: 10,
    top: 20,
    containLabel: true,
    show: true,
    borderColor: '#000'
  },
  xAxis: [{
    type: 'value',
    axisLine: {
      lineStyle: {
        color: '#000'
      }
    },
    axisLabel: {
      color: '#666'
    }
  }],
  yAxis: [{
    type: 'category',
    data: [],
    axisTick: {
      show: true
    },
    axisLine: {
      lineStyle: {
        color: '#999'
      }
    },
    axisLabel: {
      color: '#666'
    }
  }],
  series: [{
    name: '委办局统计',
    type: 'bar',
    label: {
      normal: {
        show: true,
        position: 'inside'
      }
    },
    data: [],
    itemStyle: {

    }
  }]
};

function initChart(canvas, width, height, dpr) {
  chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr // new
  });
  canvas.setChart(chart);
  return chart;
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: false,
    startDate: '',
    endDate: '',
    ec: {
      onInit: initChart
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},
  // 时间选择器返回数据
  dateChange(e) {
    this.setData({
      startDate: e.detail.startDate,
      endDate: e.detail.endDate,
    })
  },
  initData() {
    this.setData({
      loading: true
    })
    getxmTj({
      startDate: this.data.startDate,
      endDate: this.data.endDate,
    }).then(res => {
      this.setData({
        dataList: res.data,
        loading: false
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.initData()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})